<template>
    <div>
        <table>
            <tr>
                <td>名称</td>
                <td>
                    <input type="text" v-model="state.pname">
                </td>
            </tr>
            <tr>
                <td>编号</td>
                <td><input type="text" v-model="state.pbianhao"></td>
            </tr>
            <tr>
                <td>级别</td>
                <td><input type="text" v-model="state.pjibie"></td>
            </tr>
            <tr>
                <td>方案</td>
                <td>
                    <select v-model="state.pfangan">
                    <option value="请选择">请选择</option>
                    <option value="泰康保险">泰康保险</option>
                    <option value="人寿保险">人寿保险</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>消费下限</td>
                <td><input type="text" v-model="state.pjinexia"></td>
            </tr>
            <tr>
                <td>消费上限</td>
                <td><input type="text" v-model="state.pjines"></td>
            </tr>
            <tr>
                <td>
                    <input type="button" value="添加" @click="add" />
                </td>
                <td></td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import { reactive,onMounted,toRefs } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import axios from 'axios'
const route = useRoute()
const router = useRouter()
const data = reactive({
    state:{
        pname:'',
        pbianhao:'',
        pjibie:'',
        pfangan:'',
        pjinexia:'',
        pjines:''
    }
})

const {state} = toRefs(data)

const add = () => {
    if(state.value.pname=="")
    {
        alert('名称不能为空')
        return
    }
    if(state.value.pbianhao=="")
    {
        alert('编号不能为空')
        return
    }
    if(state.value.pjibie=="")
    {
        alert('级别不能为空')
        return
    }
    if(state.value.pjibie=="")
    {
        alert('消费下限不能为空')
        return
    }
    if(state.value.pjibie=="")
    {
        alert('消费上限不能为空')
        return
    }
    
    axios({
        url:'https://localhost:7284/api/Proper/AddProper',
        method:'post',
        data:state.value

    }).then((res) => {
        console.log(res);
        if(res.data.data>0)
        {
            alert('添加成功')
            router.push('/ProperShowView')
        }
        else
        {
            alert('添加失败')
        }
    })
}

</script>

<style scoped></style>